package com.chance.cc.crawler.development.bootstrap.ifeng.health.auto;


import com.alibaba.fastjson.JSON;
import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.downloader.proxy.Proxy;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRecord;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;
import org.junit.Test;

/**
 * @ClassName song
 * @Description TODO
 * @Author ding
 * @Date 2021/8/31 15:41
 * @Version 1.0
 * 开发凤凰网站点的汽车板块车系文章板块。
 *
 **/
public class IFengArticleStart {
    private static final String domain = "ifeng";
    private static Proxy proxy  = new Proxy();

    static {
        //代理配置
        //HL89Q19E86E2987D
        //71F33D94CE5F7BF2
        proxy.setHost("http-dyn.abuyun.com");
        proxy.setPort(9020);
        proxy.setUsername("HL89Q19E86E2987D");
        proxy.setPassword("71F33D94CE5F7BF2");
    }

    public static void main(String[] args) {

        /*CrawlerRequestRecord record = articleTest();


        DevCrawlerController.builder()
                .triggerInfo(domain,domain,System.currentTimeMillis(),domain)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                .consoleResultPipeline("kafka")
                .fileResultPipeline("kafka","F:\\chance_log\\ifeng\\article\\Url.log",false)
                .requestRecord(record)
                .build("com.chance.cc.crawler.development.scripts.ifeng.article")
                .start();*/
        article();

    }
    private static void article(){
        String site = "SeriesArticle";
        String url = "https://ncar.auto.ifeng.com/model/modelArticlePage?serialId=2370";
        CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpConfig(HttpConfig.me(domain))
                .httpUrl(url)
                .recordKey(url)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.comment)
                .releaseTime(System.currentTimeMillis())
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*1000,null))
                .proxy(proxy)
               // .needParsed(false)
                 .needWashed(true)
                .build();
        record.tagsCreator().bizTags().addDomain(domain);
        record.tagsCreator().bizTags().addSite(site);

        CrawlerRecord filterRecord = new CrawlerRecord();
        filterRecord.setFilter(CrawlerEnum.CrawlerRecordFilter.dateRange);
        filterRecord.addFilterInfo(FilterUtils.dateRangeFilterInfo(24*1000,null));
        record.tagsCreator().bizTags().addCustomKV("comment_record_filter_info", JSON.toJSONString(filterRecord));


        CrawlerRequestRecord keyRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPageItem)
                .httpUrl("http://192.168.1.215:9599/v1/meta/ifeng/keys?site=article")  //todo 关键字传入
                .requestLabelTag(CrawlerEnum.CrawlerRequestType.supportSource)
                .requestLabelTag(CrawlerEnum.CrawlerRequestType.internalDownload)
                .build();



        DevCrawlerController.builder()
                .triggerInfo(domain,domain,System.currentTimeMillis(),domain)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                .crawlerThreadNum(10)
                .consoleResultPipeline("kafka")
                .fileResultPipeline("kafka","F:\\chance_log\\ifeng\\article\\Url.log",false)
                .requestRecord(record)
                //.supportRecord(keyRecord)
                .build("com.chance.cc.crawler.development.scripts.ifeng")
                .start();
    }


    private static CrawlerRequestRecord articleTest(){
        String site = "article";
        String url = "https://ncar.auto.ifeng.com/model/modelArticlePage?serialId=10599";
        CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpConfig(HttpConfig.me(domain))
                .httpUrl(url)
                .recordKey(url)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.comment)
                .releaseTime(System.currentTimeMillis())
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*7,null))
                .proxy(proxy)
                .needParsed(true)
                .needWashed(false)
                .build();
        record.tagsCreator().bizTags().addDomain(domain);
        record.tagsCreator().bizTags().addSite(site);

        CrawlerRecord filterRecord = new CrawlerRecord();
        filterRecord.setFilter(CrawlerEnum.CrawlerRecordFilter.dateRange);
        filterRecord.addFilterInfo(FilterUtils.dateRangeFilterInfo(24*1,null));
        record.tagsCreator().bizTags().addCustomKV("comment_record_filter_info", JSON.toJSONString(filterRecord));
        return record;
    }
    @Test
    public void test(){
        System.out.println("\u80e1\u5e0c\u5983");
    }
}
